import React, { Component } from 'react'
import {connect} from "react-redux"
import * as action from "../action/index.js"
import { bindActionCreators } from 'redux'
const Style = {
    "flex":"1"
}
// this.props.history.location.state 路由参数对象
class Detail extends Component {
  addShop(){
     this.props.addshop( this.props.history.location.state.del)
    //  this.props.history.push({
    //      pathname:"/shopcar"
    //  })
  }
  render() {
    console.log(this.props.history,222222)
    return (
      <div style={Style} >
          {
                 this.props.history.location.state && this.props.history.location.state.del? <div>
                  <h3>{this.props.history.location.state.del.title}</h3>
                  <img src={ this.props.history.location.state.del.img} alt="" />
                  <span>价格：{this.props.history.location.state.del.price}</span>
                  <button onClick={this.addShop.bind(this)}>加入购物车</button>
              </div>:"暂无数据"
          }
      </div>
    )
  }
}
let mapStateToprops = (state)=>{
    return {
        ...state.ShopReduer
    }
}
let mapDispatchToprops = (dispatch)=> bindActionCreators(action,dispatch)
export default connect(mapStateToprops,mapDispatchToprops)(Detail)